<?php

if ($handle = opendir(APP.'/Plugin/ImageWidget/webroot/files/')) {
    $entries = array();
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            $entries[$entry] = $entry;
        }
    }
    closedir($handle);
}

echo $this->Form->create('Widget', array('type' => 'file'));
echo $this->Form->input('image', array(
    'type' => 'hidden',
    'value' => $this->Html->url(array(
            'plugin' => 'image_widget',
            'controller' => 'upload',
            'action' => 'add')).'.json',
    'id' => 'image_upload_link'));
echo $this->Form->input('value', array('type' => 'select', 'options' => $entries));
echo $this->Form->input('image', array('type' => 'file', 'id' => 'image_upload_FileInput', 'Widget'));
?>
    <button type="button" id="image_upload_button">Save Image</button>
<?php
    echo $this->Form->end('Save Widget');
?>
<div id="image_upload_progressbox" ><div id="image_upload_progressbar"></div ><div id="image_upload_statustxt">0%</div></div>
<div id="image_upload_output"></div>